import { createConnection } from 'typeorm';
import { ConfigService } from '../config/config.service';
import { DB_CONNECTION_TOKEN } from '../../const';

export const databaseProviders = [
  {
    provide: DB_CONNECTION_TOKEN,
    useFactory: async (config) => await createConnection({
      type: 'mysql',
      host: config.dbHost,
      port: config.dbPort,
      username: config.dbUser,
      password: config.dbPassword,
      database: config.dbName,
      entities: [
        __dirname + '/../**/*.entity{.ts,.js}',
      ],
      synchronize: true,
    }),
    inject: [ConfigService],
  },
];
